home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / ebreak.arc / EBREAK.ASM next >
Encoding:
Assembly Source File  |  1986-03-22  |  4.8 KB  |  222 lines

  1. ;--------------------------------------------------------------------------
  2. ;
  3. ; EBREAK v1.0 - enhanced break - Public Domain by TLG Software
  4. ;
  5. ; EBREAK is a resident program that makes the Cntl-Break key "stronger",
  6. ; so that it will even break out of tight loops which don't involve DOS
  7. ; calls.
  8. ;
  9. ; NOTE: When Cntl-Break is hit the hardware interrupts (below 20H) are
  10. ;    all reset to their values as of when the program was installed.
  11. ;    Therefore, if you are installing resident programs which steal
  12. ;    these interrupts they should be installed BEFORE this program.
  13. ;    This program steals int 09H and int 1BH.
  14. ;
  15. ;    Cntl-Break resets the system timer to run at the normal rate,
  16. ;    and restores the video mode to the state it was in when EBREAK
  17. ;    was installed.
  18. ;
  19. ;    Copyright (c) 1986 by TLG software
  20. ;         (O Cheyette, DB Clegg, M Golden)
  21. ;    This program is hereby placed into the public domain.
  22. ;    EBREAK is, however, copyrighted by the authors.  You may make
  23. ;    copies of EBREAK for your own use, and you may make copies for
  24. ;    others.
  25. ;
  26. ;    TLG software does not warrant that EBREAK operates as designed,
  27. ;    and is not liable for any damages of any kind sustained through
  28. ;    the use of the program.
  29. ;
  30. ;-------------------------------------------------------------------------
  31.  
  32. code    segment    para    public
  33.     assume    cs:code
  34.  
  35. steal_int    macro    int_num,subst_int,old_int
  36.     mov    bx,int_num * 4
  37.     mov    ax,word ptr es:[bx]
  38.     mov    word ptr old_int, ax
  39.     mov    ax,word ptr es:[bx+2]
  40.     mov    word ptr old_int[2], ax
  41.     mov    word ptr es:[bx], offset subst_int
  42.     mov    word ptr es:[bx+2], cs
  43.     endm
  44.  
  45. IntVecs    segment    at    0
  46.     org    9 * 4
  47. int_9        dd    ?
  48.     org    1Bh * 4
  49. int_1B        dd    ?
  50.     org    449H
  51. video_state    db    ?
  52. IntVecs    ends
  53.  
  54.     org    2Ch
  55. environment    label    word
  56.  
  57. BREAK_HIT    equ    1
  58.  
  59.     org    5CH
  60. DOS_1B        dd    ?    ; DOS int 1B
  61. real_int_9    dd    ?    ; keyboard handler
  62. called_cs    dw    ?
  63. break_flag    db    ?
  64. int_mask    db    ?        ; original interrupts enabled
  65. orig_int_tbl    db    80H dup(?)    ; room for copy of int tbl
  66.                     ; Note that table is on a double word
  67. initial_mode    db    ?        ; initial video mode
  68.  
  69.     org    100h
  70. start:    jmp    setup
  71.  
  72.     assume    ds:nothing, es:nothing
  73.  
  74. handle_9    proc    far        ; grabs the code segment of
  75.     push    bp            ; code executing when key was hit
  76.     mov    bp,sp
  77.     mov    bp,[bp+4]        ; code segment of caller
  78.     mov    called_cs,bp
  79.     pop    bp
  80.     mov    break_flag,0        ; clear break
  81.     pushf                ; fake an interrupt
  82.     call    real_int_9
  83.     test    break_flag,BREAK_HIT    ; did we get break?
  84.     jz    no_break
  85.  
  86.     in    al,61H            ; turn off sound
  87.     jmp    short $+2
  88.     and    al,0FCH
  89.     out    61H,al
  90.  
  91.     mov    al,36H            ; reset system timer
  92.     out    43H,al
  93.     xor    al,al
  94.     jmp    short $+2
  95.     out    40H,al
  96.     jmp    short $+2
  97.     out    40H,al
  98.  
  99.     mov    cx,40H            ; restore int tbl
  100.     push    cs
  101.     pop    ds
  102.     assume    ds:code
  103.     xor    ax,ax
  104.     mov    es,ax
  105.     assume    es:IntVecs
  106.     mov    di,ax
  107.     mov    si,offset orig_int_tbl
  108.     cli
  109.     cld
  110.     rep    movsw
  111.  
  112.     mov    al,int_mask        ; restore enabled ints
  113.     out    21H,al
  114.     sti
  115.  
  116.     mov    al,initial_mode        ; set video back to original
  117.     cmp    video_state,al
  118.     je    vid_ok
  119.     xor    ah,ah
  120.     int    10H
  121. vid_ok:
  122.  
  123.     mov    ax,4C01h        ; can we really do this?!!?
  124.     int    21H            ; YOW!
  125.  
  126. no_break:
  127.     iret                ; done
  128. handle_9    endp
  129.  
  130.  
  131. handle_1B    proc    far
  132.     assume    ds:nothing, es:nothing
  133.     push    ax
  134.     mov    ax,cs
  135.     cmp    called_cs,ax
  136.     jbe    called_from_below    ; check if were in DOS
  137.     cmp    called_cs,0A000H
  138.     jae    called_from_below    ; or in BIOS
  139.     or    break_flag,BREAK_HIT
  140. called_from_below:
  141.     pop    ax
  142.     jmp    DOS_1B            ; do DOS's int 1B
  143. handle_1B    endp
  144.  
  145. handler_end    label    byte
  146.  
  147. HANDLE_1B_LEN    equ    $ - handle_1B
  148.  
  149. installing_msg    db    'EBREAK v1.0 installed.  ',
  150. Copyright    db    'Copyright (c) 1986, TLG Software - Public Domain',
  151.         db     0Dh, 0Ah
  152. installing_msg_len    equ    $ - installing_msg
  153. not_inst_msg    db    'EBREAK previously installed.', 0Dh, 0Ah
  154. not_inst_msg_len    equ    $ - not_inst_msg
  155.  
  156.     assume    ds:code, es:nothing
  157. steal    proc    far
  158. setup:
  159.     mov    es,environment        ; free environment area
  160.     mov    ax,4900H
  161.     int    21H
  162.  
  163.     xor    ax,ax            ; set up es to IntVecs
  164.     mov    es,ax
  165.     assume    es:IntVecs
  166.  
  167.     les    di,int_1B        ; check for already installed
  168.     assume    es:nothing
  169.     mov    cx,HANDLE_1B_LEN
  170.     mov    si,di
  171.     repz    cmpsb
  172.     jcxz    already_installed
  173.  
  174.     mov    es,ax            ; point es to IntVecs again
  175.     assume    es:IntVecs
  176.  
  177.     cli
  178.     steal_int    09H,handle_9,real_int_9
  179.     steal_int    1BH,handle_1B,DOS_1B
  180.     sti
  181.  
  182.     mov    cx,40H            ; save int tbl
  183.     push    cs
  184.     pop    es
  185.     assume    es:code
  186.     xor    ax,ax
  187.     mov    ds,ax
  188.     assume    ds:IntVecs
  189.     mov    si,ax
  190.     mov    di,offset orig_int_tbl
  191.     cld
  192.     rep    movsw
  193.  
  194.     in    al,21H            ; save enabled ints
  195.     mov    int_mask,al
  196.  
  197.     mov    al,video_state        ; save video mode
  198.     mov    initial_mode,al
  199.  
  200.     push    cs
  201.     pop    ds            ; restore segment
  202.     assume    ds:code
  203.     mov    dx,offset installing_msg
  204.     mov    cx,installing_msg_len
  205.     mov    bx,1
  206.     mov    ax,4000h
  207.     int    21h
  208.     mov    dx,offset handler_end
  209.     int    27H            ; terminate and stay resident
  210.  
  211. already_installed:
  212.     mov    dx,offset not_inst_msg
  213.     mov    cx,not_inst_msg_len
  214.     mov    bx,1
  215.     mov    ax,4000h
  216.     int    21h
  217.     int    20h            ; exit, not installing code
  218. steal    endp
  219.  
  220. code    ends
  221.     end    start
  222.